//
//  MoreHouseTypeViewModel.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/4/8.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "MoreHouseTypeViewModel.h"
#import "MoreHouseTypeModel.h"
#import "MoreHouseTypeView.h"

@implementation MoreHouseTypeViewModel

#pragma mark - Delegate NetworkingBaseManagerAPISuccessCallbackDelegate
- (void)manager:(NetworkingBaseManager *)manager callAPIDidSuccessWithParams:(NSDictionary *)responseParams{
    DDLogInfo(@"查看所有户型网络返回数据：%@",[responseParams description]);
    NSArray *dataArray = [responseParams objectForKey:@"data"];
    MoreHouseTypeView *moreHouseTypeView = self.viewObject;
    NSMutableArray *models = [MoreHouseTypeModel mj_objectArrayWithKeyValuesArray:dataArray];
    
    for (MoreHouseTypeModel *model in models) {
        model.houseTypeName = [NSString stringWithFormat:@"%@户型",model.houseTypeName];
    }
    moreHouseTypeView.models = models;
}

#pragma mark - Public
- (void)loadRequest{
    self.manager = [NetworkingManagerFactory generateNormalManager];
    RequestGenerator *requestGenerator = [RequestGenerator sharedInstance];
    self.manager.apiName = [requestGenerator generateCommonApiWithName:[NSString stringWithFormat:@"projects/%ld/layouts",[AppContext sharedInstance].projectId]];
    self.manager.requestType = HTTP_GET;
    self.manager.successDelegate = self;
    self.manager.validator = self;
    [self.manager loadRequest];
}

- (void)setUpMJModel{
   [MoreHouseTypeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
       return @{
                @"houseTypeId" : @"layoutId",
                @"houseTypeName" : @"layoutNum",
                @"houseTypePicture" : @"layoutPicture"
                };
   }];
}

@end
